<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">分类设置</span>
    </div>
    <div class="control-body">
      <div class="control-section">
        <!-- 展示级数 -->
        <div class="control-item">
          <div class="control-title">
            <span>展示级数</span>
          </div>
          <div class="control-content">
            <div class="select-box">
              <a-select
                v-model="params.params.levelNum"
                @change="levelNumChange"
                class="justify-select"
              >
                <a-select-option value="1"> 一级 </a-select-option>
                <a-select-option value="2"> 二级 </a-select-option>
                <a-select-option value="3"> 三级 </a-select-option>
              </a-select>
            </div>
          </div>
        </div>
        <!-- 模板样式 -->
        <div class="control-item">
          <div class="control-title">
            <span>模板样式</span>
          </div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                @click="setStyleType(item, index)"
                :class="styleType == item.value ? 'active' : ''"
                :key="index"
              >
                <i class="iconfont" :class="item.icon" />
              </div>
            </div>
          </div>
        </div>
        <!-- 商品排列 -->
        <div class="control-item">
          <div class="control-title">
            <span>商品排列</span>
            <span class="reset" @click="resetItem('goodsShowType')">重置</span>
          </div>
          <div class="control-content">
            <div class="select-box">
              <a-select
                :default-value="params.params.goodsShowType"
                @change="goodsShowTypeChange"
                class="justify-select"
              >
                <a-select-option value="1"> 横版排列 </a-select-option>
                <a-select-option value="2"> 竖版排列 </a-select-option>
              </a-select>
            </div>
          </div>
        </div>
        <!-- 广告图片 -->
        <showModuleControl
          title="广告图片"
          :params="params"
          @reset="resetItem('showModule')"
        ></showModuleControl>
        <!-- 图片设置 -->
        <uploadImg
          :uploadImg="params.params.abConfig.imgSrc"
          size="686*154px"
          @uploadSuccess="uploadSuccess"
          @deleteImg="deleteImg"
        ></uploadImg>
        <!-- 添加连接 -->
        <div class="bg-header add-padding-bottom">
          <span>添加链接</span>
          <span class="reset" @click="resetAdLink">重置</span>
        </div>
        <chooseLink
          :link="params.params.abConfig.link"
          @chooseEnd="chooseLink"
        ></chooseLink>
      </div>
    </div>
  </div>
</template>

<script>
import { classifyContent } from "@/components/DiyNew/diy/systemPages/classifyPage/dataConfig/config.js";
import showModuleControl from "@/components/DiyNew/diy/baseControl/showModuleControl/index.vue";
import uploadImg from "@/components/DiyNew/uploadImg/index.vue";
import chooseLink from "@/components/DiyNew/chooseLink/index.vue";

export default {
  name: "classifyContentControl",
  components: {
    showModuleControl,
    uploadImg,
    chooseLink,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      levelOne: [
        { icon: 'icon-yijifenlei-zuocefenlei', value: 7 },
        { icon: 'icon-yijifenlei-shangcefenlei', value: 8 },
        { icon: 'icon-yijifenlei-tupianfenlei', value: 9 },
      ],
      levelTwo: [
        { icon: 'icon-erjifenlei-shangpinfenlei-1', value: 1 },
        { icon: 'icon-erjifenlei-shangpinfenlei', value: 2 },
        { icon: 'icon-erjifenlei-dingbufenlei', value: 3 },
        { icon: 'icon-erjifenlei-tupianfenlei', value: 4 },
        { icon: 'icon-erjifenlei-hengtufenlei', value: 5 },
      ],
      levelThree: [{ icon: 'icon-sanjifenlei-tupianfenlei', value: 6 }],
      exampleList: [],
    };
  },
  watch: {},
  computed: {
    styleType: {
      get() {
        return this.params.params.styleType || "1";
      },
    },
  },
  mounted() {
    console.log("传进来的值", this.params);
    this.exampleList = this.levelOne;
    if (this.params.params.styleType) {
      let [inOne] = this.levelOne.filter((d) => {
        return d.value == this.params.params.styleType;
      });
      let [inTwo] = this.levelTwo.filter((d) => {
        return d.value == this.params.params.styleType;
      });
      let [inThree] = this.levelThree.filter((d) => {
        return d.value == this.params.params.styleType;
      });
      if (inOne) {
        this.exampleList = this.levelOne;
        this.$set(this.params.params, "levelNum", "1");
      }
      if (inTwo) {
        this.exampleList = this.levelTwo;
        this.$set(this.params.params, "levelNum", "2");
      }
      if (inThree) {
        this.exampleList = this.levelThree;
        this.$set(this.params.params, "levelNum", "3");
      }
    }
  },
  methods: {
    // 设置样式
    setStyleType(item, index) {
      this.$setWithAction(this.params, "styleType", item.value);
    },
    setWithActionItem(e, key) {
      this.$setWithAction(this.params, key, e);
    },
    levelNumChange(e) {
      this.setWithActionItem(e, "levelNum");
      let arr = ["", this.levelOne, this.levelTwo, this.levelThree];
      this.exampleList = arr[e];
    },
    goodsShowTypeChange(e) {
      this.setWithActionItem(e, "goodsShowType");
    },
    uploadSuccess(e) {
      console.log(e);
      this.$set(this.params.params.abConfig, "imgSrc", e.val);
    },
    deleteImg() {
      this.$set(this.params.params.abConfig, "imgSrc", "");
    },
    chooseLink(e) {
      this.$set(this.params.params.abConfig, "link", e);
    },
    resetAdLink() {
      this.$set(this.params.params.abConfig, "link", {});
    },
    resetItem(key) {
      let data = Object.assign({}, classifyContent);
      this.$set(this.params.params, key, data.params[key]);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    padding-bottom: 20px;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .reset {
            font-size: 12px;
            font-weight: 400;
            color: #8e8e8e;
            cursor: pointer;
          }
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 8px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              margin-bottom: 8px;
              overflow: hidden;
              .iconfont {
                font-size: 60px;
              }
            }
            .active {
              border: 2px solid #1890fc;
            }
            .example-item:nth-child(3n + 3) {
              margin-right: 0;
            }
          }
          .select-box {
            width: 100%;
            .justify-select {
              width: 100%;
              height: 100%;
              ::v-deep .ant-select-selection--single {
                height: 100%;
                border: 0 none;
                background: #f2f2f2;
              }
              ::v-deep .ant-select-selection__rendered {
                line-height: 40px;
              }
            }
          }
        }
      }
      .bg-header {
        width: 100%;
        padding: 24px 0 0 0;
        font-size: 12px;
        color: #000000;
        text-align: left;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .reset {
          font-size: 12px;
          font-weight: 400;
          color: #8e8e8e;
          cursor: pointer;
        }
      }
      .add-padding-bottom {
        padding-bottom: 14px;
      }
    }
  }
}
</style>
